home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’87 / Source ƒ.sit / Source ƒ / C ƒ / CITADEL BBS 'C' SRC / LIBCRYP.C < prev    next >
C/C++ Source or Header  |  1987-01-14  |  2KB  |  47 lines

  1. /************************************************************************/
  2. /*                libCryp.c                */
  3. /*                                    */
  4. /*              Library of encryption for Citadel         */
  5. /************************************************************************/
  6.  
  7. /************************************************************************/
  8. /*                history                 */
  9. /*                                    */
  10. /* 85Nov15 HAW    Created.                        */
  11. /************************************************************************/
  12.  
  13. #include "ctdl.h"
  14.  
  15. /************************************************************************/
  16. /*                contents                */
  17. /*                                    */
  18. /*    crypte()        encrypts/decrypts data blocks        */
  19. /************************************************************************/
  20.  
  21. extern struct config cfg;        /* Configuration variables    */
  22.  
  23. /************************************************************************/
  24. /*    crypte() encrypts/decrypts data blocks                */
  25. /*                                    */
  26. /*  This was at first using a full multiply/add pseudo-random sequence    */
  27. /*  generator, but 8080s don't like to multiply.  Slowed down I/O    */
  28. /*  noticably.    Rewrote for speed.                    */
  29. /*    84Sep04 HAW  I'll just use it......                */
  30. /************************************************************************/
  31. crypte(buf, len, seed)
  32. unsigned char *buf;
  33. unsigned      len, seed;
  34. {
  35.     static unsigned char *b;    /* Make this static for speed (I guess),*/
  36.     static  int c, s;        /* since register variables not around    */
  37.  
  38.     seed    = (seed + cfg.cryptSeed) & 0xFF;
  39.     b        = buf;
  40.     c        = len;
  41.     s        = seed;
  42.     for (;  c;    c--) {
  43.     *b++   ^= s;
  44.     s    = (s + CRYPTADD)  &  0xFF;
  45.     }
  46. }
  47.